//
//  ToastView.m
//  MoneyLove
//
//  Created by Mac on 2018/6/21.
//  Copyright © 2018年 Mac. All rights reserved.
//

#import "ToastView.h"
#import <MBProgressHUD.h>
#import "UIImage+GIF.h"
#import "CustomView.h"

@implementation ToastView


+ (void)tip:(NSString *)msg{
    [ToastView dismiss];
    [self showTipToView:nil title:nil msg:msg mode:MBProgressHUDModeText animation:MBProgressHUDAnimationFade gif:0];
}


+ (void)dismiss{
    [self hideHUDForView:nil];
}

+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) {
        view = (UIView*)[UIApplication sharedApplication].delegate.window;
    }
    [MBProgressHUD hideHUDForView:view animated:YES];
}


- (void)hideHUDForView:(UIView *)view
{
    if (view == nil) {
        view = (UIView*)[UIApplication sharedApplication].delegate.window;
    }
    [MBProgressHUD hideHUDForView:view animated:YES];
}

/**
 菊花展示
 */
+ (void)show{
    [self showTipToView:nil title:nil msg:nil mode:MBProgressHUDModeIndeterminate animation:MBProgressHUDAnimationFade gif:0];
}

/**
 Gif展示
 */
+ (void)showGif{
    [self showTipToView:nil title:nil msg:nil mode:MBProgressHUDModeIndeterminate animation:MBProgressHUDAnimationFade gif:1];
}

+ (void)showTitle:(NSString *)title{
    [self showTipToView:nil title:title msg:nil mode:MBProgressHUDModeIndeterminate animation:MBProgressHUDAnimationFade gif:0];
}

+ (void)showTipToView:(UIView *)view title:(NSString *)title msg:(NSString *)msg mode:(MBProgressHUDMode)mode animation:(MBProgressHUDAnimation)animation gif:(NSInteger )gif
{
    if (view == nil)
    {
        view = (UIView *)[UIApplication sharedApplication].delegate.window;
    }
    MBProgressHUD *hud;
    
    if(gif == 1){
        [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor clearColor];
        hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
        hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        hud.bezelView.backgroundColor = [UIColor clearColor];
        hud.mode = MBProgressHUDModeCustomView;
        hud.animationType = animation;
        hud.backgroundColor = [UIColor clearColor];
        hud.customView = [[CustomView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    }else{
        [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor whiteColor];
        hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
        hud.mode = mode;
        hud.animationType = animation;
        //hud.bezelView.backgroundColor = [UIColor blackColor];
        hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        hud.bezelView.color = [UIColor darkGrayColor];

        hud.detailsLabel.text = msg;
        hud.label.text = title;
        hud.label.textColor = [UIColor whiteColor];
        hud.label.font = [UIFont systemFontOfSize:16];
        hud.detailsLabel.font = [UIFont systemFontOfSize:14];
        hud.detailsLabel.textColor = [UIColor whiteColor];
    }
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    if (mode == MBProgressHUDModeText) {
        [hud hideAnimated:YES afterDelay:1.5];
    }
    
}


+ (void )showWarnnigInfo:(NSString *)warnningInfo{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];//设置HUD的Style
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];//设置HUD和文本的颜色
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];//设置HUD的背景颜色
    [SVProgressHUD showInfoWithStatus:warnningInfo];
    [SVProgressHUD dismissWithDelay:1.2];
}
@end
